package com.leeyu.rabbitmq.listener;

import com.leeyu.rabbitmq.config.RabbitMQConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

//@Component
public class ConsumeListener {

    @RabbitListener(queues = RabbitMQConfig.QUEUE)
    public void consume(String msg, Channel channel, Message message) throws IOException {
        System.out.println("消费消息：" + msg);

        String correlationId = message.getMessageProperties().getCorrelationId();
        System.out.println("消息唯一标识：" + correlationId);

        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

    }

}
